package routers

import (
	"HermesLinkGo/handler"
	"HermesLinkGo/middlewares"
	"HermesLinkGo/setting"
	"github.com/gin-gonic/gin"
)

func InitRouter() *gin.Engine {
	r := gin.Default()
	r.BasePath()
	gin.SetMode(setting.ServerSetting.RunMode)
	r.Use(middlewares.Cors())

	r.GET("/", func(c *gin.Context) {
		c.Writer.WriteHeader(200)
		_, _ = c.Writer.Write([]byte("<html><body>star on <a href=\"https://github.com/zhangyunan1994/ChattyAI\"><img alt=\"GitHub Repo stars\" src=\"https://img.shields.io/github/stars/zhangyunan1994/chattyai?style=social\"></a></body></html>"))
		c.Writer.Header().Add("Accept", "text/html")
		c.Writer.Flush()
	})

	apiGroup := r.Group("/api")
	{
		{
			authGroup := apiGroup.Group("auth")
			authGroup.POST("login/withPassword", handler.LoginByPassword)
			authGroup.GET("checkToken", handler.AuthCheckToken)
		}
		{
			memberGroup := apiGroup.Group("member")
			memberGroup.Use(middlewares.Auth("member"))
			memberGroup.GET("info", handler.GetMemberInfo)
		}
	}

	return r
}
